package com.zfk.transaction.service.impl;

import com.alibaba.fastjson.JSON;
import com.zfk.transaction.entity.chat.ChatContent;
import com.zfk.transaction.entity.chat.ChatSeller;
import com.zfk.transaction.mapper.ChatMapper;
import com.zfk.transaction.service.ChatService;
import com.zfk.transaction.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.unit.DataUnit;

import java.util.List;

@Service
public class ChatServiceImpl implements ChatService {

    @Autowired
    private ChatMapper mapper;


    /**
     * 获得当前用户的聊天列表
     * @param user_id
     * @return
     */
    @Override
    public List<ChatSeller> getChatByUserId(int user_id) {
        return mapper.getChatByUserId(user_id);
    }

    /**
     * 获得当前用户与该商家的聊天记录
     * @param user_id
     * @param seller_id
     * @return
     */
    @Override
    public List<ChatContent> getChatMessage(int user_id, int seller_id) {
        List<ChatContent> chatMessage = mapper.getChatMessage(user_id, seller_id);
        // 根据date排序
        DateUtil.sort(chatMessage);

        return chatMessage;
    }
    /**
     * 点击联系商家，需要更新用户的聊天列表
     */
    @Override
    public int addChatSeller(ChatSeller chatSeller) {
        return mapper.addChatSeller(chatSeller);
    }


    /**
     * 删除用户与某个商家的聊天
     * @param id
     * @return
     */
    @Override
    public int deleteChatSeller(int id) {
        return mapper.deleteChatSeller(id);
    }

    @Override
    public int addChatContent(ChatContent chatContent) {
        return mapper.addChatContent(chatContent);
    }
}
